<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Projects_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function get_by_id($project_id) {
        return $this->db->get_where('projects', array('id' => $project_id))->row();
    }

    function get_for_class($class_id) {
        return $this->db->get_where('projects', array('class_id' => $class_id))->result();
    }

    function create($start_date, $end_date, $title, $content) {
        $this->db->set('user_id', $this->tank_auth->get_user_id());
        $this->db->set('created', 'now()', false);
        $this->db->set('title', $title);
        $this->db->set('content', $content);
        $this->db->insert('projects');
    }

    function update($project_id, $start_date, $end_date, $title, $content) {
        $data = array(
            'start_date' => $start_date,
            'end_date' => $end_date,
            'title' => $title,
            'content' => $content,
        );
        $this->db->update('projects', $data, array('id' => $project_id));
    }

    function delete($project_id) {
        $this->db->delete('projects', array('id' => $project_id));
    }
}